#include "EasyFunAny_1.h"

namespace Solver
{

EasyFunAny_1::EasyFunAny_1(std::size_t dim):BaseFun(dim, FunType_E::EasyAny_1_E, DifficultyLevel_E::Easy_E, 1, "EasyFunAny_1", "")
{
    //1. 最优解
    passY_ = 1e-12;
    bestY_ = 0;
    for (std::size_t i = 0; i != dim; ++i)
    {
        bestX_[i] = i;
    }

    //2. 设置初始求解范围[-10000,10000]
    const value_t v = dim < 10000 ? 10000 : dim + 1;
    setXRange(-v, v);

    //3. 添加一些描述
    description_ = "本函数是一个凸函数,求解比较简单";
}

EasyFunAny_1::~EasyFunAny_1()
{

}

value_t EasyFunAny_1::calcFun(const VectorXd_t &x)
{
    //1.
    const std::size_t num = x.size();
    if (x.size() != bestX_.size())
    {
        return std::numeric_limits<value_t>::max();
    }

    //2.
    value_t sum(0);
    for (std::size_t i = 0; i != num; ++i)
    {
        sum += std::pow(bestX_[i] - x[i], 2);
    }

    return sum;
}

}